<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!-- http://jstl.java.net/ tuleb tommata ja WEB-INF/lib kataloogi et yloemine rida toimiks -->
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>    
<%@ page import="java.util.*"  %>   
<%@page import="idu0080.yl6_OpenERPServices_client.Invoice"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>Payment</title>
	</head>
	<body>
		<script>
		
			function makePayment()
			{
				document.forms[0].what_to_do.value = "makePayment";
				document.forms[0].submit();
			}	
			
		</script>
		
		<a href=index.html>index</a><br>
		<%
		
		if (request.getAttribute("paymentNumber") != null && !request.getAttribute("paymentNumber").equals("-1"))
		{
			out.println("<p style='color:red;'><b>Makse tehtud: " + (String) request.getAttribute("paymentNumber") + "</b></p>" );
		}

		if (request.getAttribute("SOAP_ERROR_CODE") != null)
		{
			out.println("SOAP_ERROR_CODE: <b>" + (String) request.getAttribute("SOAP_ERROR_CODE") + "</b><br>" );
		}
		
		if (request.getAttribute("SOAP_ERROR_MESSAGE") != null)
		{
			out.println("SOAP_ERROR_MESSAGE: <b>" + (String) request.getAttribute("SOAP_ERROR_MESSAGE") + "</b><br>" );
		}
		
		%>
		
		<form action=payment method="post">
			<% 
			String selectedInvoiceId = null;
			String selectedInvoiceNumber = null;
			Invoice selectedInvoice = null;
			
			if (request.getAttribute("selectedInvoiceId") != null)
			{
				selectedInvoiceId = (String) request.getAttribute("selectedInvoiceId");
			}
			else
			{
				selectedInvoiceId = "";
			}
			
			if (request.getAttribute("selectedInvoiceNumber") != null)
			{
				selectedInvoiceNumber = (String) request.getAttribute("selectedInvoiceNumber");
			}
			else
			{
				selectedInvoiceNumber = "";
			}
			%>
			
			<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor=#ccccccc>Otsi:arve number:<input type=text name=selectedInvoiceNumber value="<%=selectedInvoiceNumber%>"></td></tr>
			<tr><td bgcolor=#ccccccc><input type=submit value='Otsi'></td><td></td></tr></table>
			<br><br>
			<input type=hidden name=selectedInvoiceId value="<%=selectedInvoiceId%>">
			<input type=hidden name=what_to_do value="">
			<%
			if (request.getAttribute("selectedInvoice") != null)
			{
				selectedInvoice = (Invoice) request.getAttribute("selectedInvoice") ;
				out.println("<table>");
				out.println("<tr><td bgcolor=#ccccccc colspan=7>Leitud arve number: <b>" + selectedInvoice.getNumber() + "</b> [id:<b>" + Integer.toString(selectedInvoice.getInvoiceId()) + "</b>]</td></tr>");
			    out.println("<tr><td bgcolor=#ccccccc></td><td bgcolor=#ccccccc>kogusumma:</td><td><b>" + Double.toString(selectedInvoice.getAmountTotal()) + "</b></td><td bgcolor=#ccccccc>Maksmata </td><td>:<b>" +  Double.toString(selectedInvoice.getResidual()) + "</b></td><td bgcolor=#ccccccc>seisund:</td><td><b>" + selectedInvoice.getState() + "</b></td></tr>" );
				out.println("<tr><td bgcolor=#ccccccc>Raha kassasse:</td><td><input type='text' name=paydAmount value=''></td>");
			    out.println("<td bgcolor=#ccccccc colspan=5><input type=button onClick=\"javascript:makePayment()\" value='Maksan'></td></tr></table>");
			}
			
			%>
		</form>
	</body>
</html>